package com.example.accessingdatajpa.repository;

import com.example.accessingdatajpa.pojo.Customer;
import com.example.accessingdatajpa.pojo.ShoppingCart;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface ShoppingCartRepository extends JpaRepository<ShoppingCart,Long> {

    ShoppingCart findByGoodsTitleAndCustomer_CustomerIdAndIsSubmit(String goodsTitle, Long customerId,Boolean isSubmit);
    List<ShoppingCart> findByCustomer_CustomerId(Long customerId);
    List<ShoppingCart> findByCustomer_CustomerIdAndIsSubmit(Long customerId,Boolean isSubmit);
    List<ShoppingCart> findByCustomer_CustomerIdAndIsSubmitAndOrderManagement(Long customerId,Boolean isSubmit,Integer orderManagement);

    @Modifying
    @Transactional
    @Query("update ShoppingCart shoppingCart set shoppingCart.goodsAmount=?1 where shoppingCart.shoppingId=?2")
    Integer updateGoodsAmount(Long goodsAmount,Long shoppingId);

    @Modifying
    @Transactional
    @Query("update ShoppingCart shoppingCart set shoppingCart.goodsSelect=?1 where shoppingCart.shoppingId=?2")
    Integer updateGoodsSelect(Boolean goodsSelect,Long shoppingId);
}
